
<title>运费核销</title>


<div class="layui-fluid" style="padding: 15px">
    <div class="layui-card" style="padding-top: 10px">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form" method="post" action="">
                    <div class="layui-row">
                        <div class="layui-col-xs3">
                            <div class="grid-demo grid-demo-bg1">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">托运单号：</label>
                                    <div class="layui-input-block" style="width:180px;">
                                        <input type="text" name="checkenumber" lay-verify="required" autocomplete="off"
                                               placeholder="请输入" class="layui-input">
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo">

                                <div class="layui-form-item">
                                    <label class="layui-form-label">外包单号：</label>
                                    <div class="layui-input-block" style="width:180px;">
                                        <input type="text" name="outsourcingnumber" lay-verify="title" autocomplete="off"
                                               placeholder="请输入" class="layui-input">
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo grid-demo-bg1">

                                <div class="layui-form-item">
                                    <label class="layui-form-label">外包公司：</label>
                                    <div class="layui-input-block" style="width:180px;">
                                        <select name="outsourcingcompany" id="outsourcingcompany"  lay-search="">
                                            <option value=""></option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo">

                                <div class="layui-form-item">
                                    <label class="layui-form-label">转包日期：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="subcontractingdate" id="subcontractingdate" lay-verify="date1"
                                               placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-xs12" style="height:30px">
                            <div class="grid-demo">
                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit
                                            lay-filter="formDemo">外包查询
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="layui-row">
                    <table class="layui-hide" id="verificationlist" lay-filter="verificationlist"></table>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="verification">提货核销</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancelwrite">反核销</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate','table'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table = layui.table;
        var $ = layui.jquery;


        var tableIns=table.render({
            elem: '#verificationlist'
            ,url:'../../queryDeliveryverification'
            ,title: '派送核销数据表'
            ,height:420
            ,cols: [[
                {type:'checkbox'}
                ,{field:'primaryconsignmentnumber', title:'原托运单号', width:150, sort: true}
                ,{field:'shipdate', title:'发货日期', width:150}
                ,{field:'reachsubstation', title:'到达分站', width:150}
                ,{field:'shippingnumber', title:'运输单号', width:150}
                ,{field:'transporternumber', title:'运输车号', width:150}
                ,{field:'drivername', title:'司机姓名', width:150}
                ,{field:'deliveryfee', title:'提货开支', width:150}
                ,{field:'receivable', title:'应收', width:150}
                ,{field:'uncollected', title:'已收', width:150}
                ,{field:'reachcity', title:'到达城市', width:170}
                ,{field:'forwardingunit', title:'发货单位', width:150}
                ,{field:'goodsname', title:'货物名称', width:150}
                ,{field:'goodsquantity', title:'货物数量', width:150}
                ,{field:'goodsvolume', title:'货物体积', width:150}
                ,{field:'settlementstate', title:'结算状态', width:150}
                ,{field:'verificationstate', title:'核销状态', width:150}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });
        //监听行工具事件
        table.on('tool(verificationlist)',function (obj) {
            switch (obj.event) {
                case 'verification':
                    if(obj.data.settlementstate=="已结清"){
                        alert("已结清完毕无需再次结算")
                        break;
                    }else {
                        var waybillid=obj.data.primaryconsignmentnumber;
                        verificationDate(waybillid);
                        break;
                    }
                case 'cancelwrite':
                    if(obj.data.verificationstate=="已核销" ||obj.data.verificationstate=="true" ){
                        alert("已核销无需再次核销")
                        break;
                    }else {
                        var waybillid = obj.data.primaryconsignmentnumber;
                        cancelwriteDate(waybillid);
                        break;
                    }
                default:
                    break;
            }
        })

        /*表单提交*/
        form.on('submit(formDemo)', function(data){
            tableIns.reload({
                type:'post'
                ,url:'../../conditionalqueryOther',
                where: {
                    //设定异步数据接口的额外参数，任意设
                    checkenumber:data.field.checkenumber
                    ,outsourcingnumber:data.field.outsourcingnumber
                    ,outsourcingcompany:data.field.outsourcingcompany
                    ,subcontractingdate:data.field.subcontractingdate
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });

        /*结算核销*/
        function cancelwriteDate(waybillid) {
            layui.use(['layer','table','jquery'], function(){
                var layer = layui.layer;
                var table = layui.table;
                var $ = layui.jquery;
                layer.open({
                    content: '测试回调',
                    //大小
                    area:['300px', '180px'],
                    btn: ['确定','取消'],
                    content: '确定要提交核销?',
                    yes: function(index,kskks){
                        $.ajax({
                            url:'../../updateFinanceverification',
                            type:'post',
                            dataType:'text',
                            data:{
                                waybillid:waybillid
                            },
                            success:function(data){
                                //表刷新方法
                                alert(data);
                                reloads();
                            }
                        });
                        layer.close(index);
                    }

                });
            });
        }

        /*修改其它外包信息*/
        function verificationDate(waybillid) {
            layui.use(['table','jquery','form'], function(){
                var form = layui.form;
                var table = layui.table;
                var $ = layui.jquery;
                $.ajax({
                    url : '../../getCostbreakdownByid',
                    method : 'post',
                    data :{
                        waybillid:waybillid
                    } ,
                    dataType:"json",
                    success:function(data) {
                        verificationpopup();
                        setTimeout(function () {
                            //jquery获取内嵌框架对象
                            var cation = $("#cation").contents();
                            cation.find("#costbreakdownId").val(data.costbreakdownId);
                            cation.find("#receivables").val(data.receivables);
                            cation.find("#owefee").val(data.owefee);
                            cation.find("#shippingaddress").val(data.shippingaddress);
                        }, 500);
                    }
                });
            });
        }

        /*弹出层提货核销*/
        function verificationpopup(){
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.open({
                    skin:'layui-layer-molv',//皮肤
                    content: '测试回调',
                    //大小
                    area:['90%', '650px'],
                    btn: [],
                    content: '<iframe src="../src/views/finance/iframe/verification.html" id="cation" width="100%" height="100%" frameborder="0"/>',
                    closeBtn: 2, //关闭按钮样式默认1
                    anim:4 //设置关闭动画
                });
            });
        }

        /* 表刷新方法 */
        function reloads(){
            layui.use('layer', function(){
                var table = layui.table;
                table.reload("verificationlist");
            });
        }
    });
</script>